<template>
  <div class="shopcar-container">
    <van-swipe-cell v-for="item in cartList" :key="item.id">
      <div class="shopcart-box">
        <van-checkbox
          @click="checkedCell"
          v-model="item.checked"
          checked-color="#F63515"
          class="checked"
        ></van-checkbox>
        <div class="cell" @click="pushDetal">
          <img :src="item.imageHost + item.mainImage" />
          <div class="shopcart-item-info">
            <p class="shopcart-name">
              {{ item.name }}
            </p>
            <p class="shopcart-subtitle">{{ item.subtitle }}</p>
            <div class="shopcart-stepper">
              <span class="shopcart-price">￥{{ item.price }}</span>
              <van-stepper
                v-model="item.count"
                @plus="handPlus"
                min="1"
                max="8"
              />
            </div>
          </div>
        </div>
      </div>
      <template slot="right">
        <van-button square type="danger" text="删除" />
      </template>
    </van-swipe-cell>
  </div>
</template>

<script>
export default {
  props: {
    cartList: {
      type: Array,
    },
  },
  data() {
    return {
      checked: false,
      value: 1,
    };
  },
  methods: {
    handPlus(e) {
      // stopPropagation
      console.log("点击加号", e);
    },
    checkedCell() {
      // console.log("-----", this.cartList);
      this.$store.dispatch("changeChecked");
    },
    pushDetal(e) {
      console.log(e);
      if (e.target.className.indexOf("stepper") != -1) {
        console.log("stepper");
      } else {
        console.log("跳转详情页面");
      }
    },
  },
};
</script>

<style lang="scss" scoped>
@import "@/common/style/mixin.scss";

.shopcar-container {
  margin-top: 110px;
  .shopcart-box {
    display: flex;
    justify-content: space-around;
    background: #fff;
    padding: 10px;
    margin: 10px 0;
    height: 200px;

    .checked {
      width: 40px;
    }
    .cell {
      flex: 1;
      display: flex;
      justify-content: space-around;
      background: #fff;
      height: 200px;
    }
    img {
      width: 180px;
      height: 180px;
      margin: 0 10px;
    }

    .shopcart-item-info {
      display: flex;
      flex: 70%;
      flex-direction: column;
      justify-content: space-between;

      .shopcart-name {
        height: 70px;
        font-size: 26px;
        overflow: hidden;
      }

      .shopcart-subtitle {
        font-size: 24px;
        color: #999;
      }

      .shopcart-stepper {
        display: flex;
        justify-content: space-between;
        align-items: center;

        .shopcart-price {
          font-size: 30px;
          color: $red;
        }
      }
    }
  }
  .van-button {
    height: 200px;
  }
}
</style>